package com.example.wxchatdemo.Sockets;


import android.graphics.Color;
import android.graphics.fonts.Font;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

public class TestClient {
    private Socket socket;
    private InputStream is;
    private OutputStream os;
    private String response = "";
    private Scanner scanner;
    private  String msgs;

    public String getMsgs() {
        return msgs;
    }

    public void setMsgs(String msgs) {
        this.msgs = msgs;
    }

    public void init() throws IOException {
        try {
            socket = new Socket("100.2.182.47", 8888);
            is = socket.getInputStream();
            os = socket.getOutputStream();
        } catch (IOException e) {
            e.printStackTrace();
        }
        response = IOUtil.readString(is);

           /* public void actionPerformed(String w) {
                IOUtil.writeString(os,"w");
            }*/
//发送消息到服务器
        IOUtil.writeString(os,"sta 你好，我是帅哥");
        recive();


    }


    public void recive() throws IOException {
        while (true){
            String s = IOUtil.readString(is);
            response = s+"\n";
            setMsgs(response);
            System.out.println("接收数据是："+response);
            if (socket.isClosed()){
                System.out.println("连接或服务器已关闭");
                break;
            }
        }
    }

    public static void main(String[] args) throws IOException {
        TestClient t = new TestClient();
        t.init();
    }
}
